package LeetCode.LC17;

import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import java.util.Queue;

/**
 * @author corn
 * @create 2020-11-08-14:48
 */
public class Solution_queue {
    private List<String> orders = new ArrayList<>();
    private List<String> letters = new ArrayList<>();
    private Queue<String> queue = new LinkedList<>();
    public List<String> letterCombinations(String digits) {
        if(digits.equals("")){
            return orders;
        }
        letters.add("abc");
        letters.add("def");
        letters.add("ghi");
        letters.add("jkl");
        letters.add("mno");
        letters.add("pqrs");
        letters.add("tuv");
        letters.add("wxyz");
        char c1 = digits.charAt(0);
        int a = c1 -'0';
        String letter1 = letters.get(a-2);
        for (char l : letter1.toCharArray()) {
            queue.add(String.valueOf(l));
        }
        for(int i = 1; i< digits.length(); i++){
            int d = digits.charAt(i) -'0';
            String letter = letters.get(d-2);
            int size = queue.size();
            for(int j = 0; j < size; j++){
                String s = queue.poll();
                for (char l : letter.toCharArray()) {
                    queue.add(s + l);
                }
            }
        }
        orders.addAll(queue);
        return orders;
    }
}
